package com.cskaoyan.day6;

import java.util.Scanner;

public class TwoDimensionalArray2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[][] score = new int[3][];
        score[0] = new int[3];
        score[1] = new int[2];
        score[2] = new int[5];
        System.out.println("请分别录入1班三人成绩：");
        for (int i = 0; i < 3; i++) {
            score[0][i] = sc.nextInt();
        }
        System.out.println("请分别录入2班两人成绩：");
        for (int i = 0; i < 2; i++) {
            score[1][i] = sc.nextInt();
        }
        System.out.println("请分别录入5班五人成绩：");
        for (int i = 0; i < 5; i++) {
            score[2][i] = sc.nextInt();
        }
        printAvgSocre(score);
        System.out.println();
        System.out.println("-----------------------------------");
        System.out.println();
        sortAvgAndPrint(score);
    }

    private static void sortAvgAndPrint(int[][] score) {
        for (int i = 0; i < score.length; i++) {
            double max= score[0][0];
            double min= score[0][0];
            for (int j = 0; j < score[i].length; j++) {
                if(max <score[i][j]){
                    max=score[i][j];
                }
                if(min>score[i][j]){
                    min=score[i][j];
                }
            }
            System.out.println(i+1+"班最低成绩为："+min+"\t,最高成绩为:"+max);
        }
    }

    private static void printAvgSocre(int[][] score) {
        for (int i = 0; i < score.length; i++) {
            double scoreSum = 0;
            for (int j = 0; j < score[i].length; j++) {
                scoreSum+=score[i][j];
            }
            System.out.println(i+1+"班平均成绩为："+scoreSum/score[i].length);
        }
    }
}
